package cn.xiuxius.embedded.toolwindow.model;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

@Accessors(chain = true)
@Getter
@Setter
public abstract class AbstractCommandOption<T> implements CommandOption {

    private String cmdFlag;
    private String defaultValue;
    private String cmdValue;
    private boolean onlyFlag;
    private String description = "";
    private List<String> options = new ArrayList<>();
    private boolean advanced = false;
    private Supplier<List<String>> refreshProvider;

    public AbstractCommandOption(String cmdFlag, String defaultValue, boolean onlyFlag) {
        this.cmdFlag = cmdFlag;
        this.defaultValue = defaultValue;
        this.cmdValue = defaultValue;
        this.onlyFlag = onlyFlag;
    }

    public abstract AbstractCommandOption<T> options(Supplier<List<T>> provider);


    public CommandOption advanced() {
        advanced = true;
        return this;
    }
    @Override
    public boolean isDefault() {
        return cmdValue.equals(defaultValue);
    }


    @Override
    public List<Selectable> getSelectables() {
        if (refreshProvider != null) {
            return Selectable.from(refreshProvider.get());
        }
        return Selectable.from(options);
    }

    @Override
    public boolean isValidValue(String value) {
        return true;
    }
}
